Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add description to inspections. #281

Merged
merged 21 commits into from
Mar 12, 2020
Merged

Conversation

mwz
Copy link
Contributor

@mwz mwz commented Mar 5, 2020

@sksamuel @mccartney I've started adding descriptions to inspections, but I wanted to check with you first if you're happy with this approach before I do this for all of the inspections. I've opened this draft with just few inspections updated as an example.

Here are the key changes:
I've added a description to the Inspection class and made the explanation non-optional - I think every inspection should have it. I'm also planning to remove code snippets from all the inspections and just use the description to create each warning (maybe except for some cases where the message can be more specific, e.g. the CollectionNamingConfusion).

It might take a while to apply those changes across all of the inspections, so I wanted to make sure you're both happy with this approach before I invest the time into this PR.

Relates to #219.

@mccartney
Copy link
Collaborator

I like it!

@mccartney
Copy link
Collaborator

Is there any way to cooperate with you on this one? I find it hard to guess where you are on this one - e.g. is there some range of inspections we could take care of (by adding texts)?

@mwz
Copy link
Contributor Author

mwz commented Mar 11, 2020

Is there any way to cooperate with you on this one? I find it hard to guess where you are on this one - e.g. is there some range of inspections we could take care of (by adding texts)?

Thanks for asking, @mccartney - I think this is finished now. Here's a brief summary:

  1. I've updated all of the inspections with an additional explanation and I hope I also made the descriptions more consistent across the board, but please review thoroughly as it's easy to miss something or make a mistake when you're changing 170 files 😄
  2. I also initially removed printing code snippets, but I realised they were quite useful, so I added them back in, but I separated them from the descriptions.
  3. I've tried to make as little changes as possible, but you'll probably notice a tiny tiny bit of reformatting (but it should be mostly just whitespaces/new lines). (I'd like to add scalafmt to this project and autoformat the entire codebase in a separate PR if that's ok with you guys.)
  4. I removed all of the empty/non-implemented inspections, which I will raise separate issues for so we can keep track of should anyone want to implement them in the future.
  5. I removed 2.13.0 from the build matrix in travis as it looks like the build is failing for this version (I'm assuming due to some sort of regression in 2.13.0 that was fixed in 2.13.1?). I think since the artifacts are not published for 2.13, we're safe to remove it from the build. Any thoughts? I can see you raised a separate issue about it @mccartney (Travis builds for 2.13.0 fail #298).
  6. I've come across some false positives for VarClosure when testing a snapshot against some other projects - I'll raise a separate issue about it as it's not related to this PR (and this has not been released yet as far as I can see).
  7. I want to do a little bit more testing to check a few other things before I can say I'm happy with these changes, but I'll mark it as ready for review as I'm not expecting any other major changes from my end.

@mwz mwz marked this pull request as ready for review March 11, 2020 00:13
@mwz mwz changed the title WIP Add description to inspections. Add description to inspections. Mar 11, 2020
@mccartney mccartney self-requested a review March 11, 2020 06:25
@mwz
Copy link
Contributor Author

mwz commented Mar 11, 2020

Since #298 is now addressed, I'll add 2.13.0 back to the build matrix.

Copy link
Collaborator

@mccartney mccartney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some minor adjustments to the explanations.

text = "Missing final modifier on case class",
defaultLevel = Levels.Info,
description = "Checks for case classes without a final modifier.",
explanation = "Using case classes without final modifier can lead to surprising breakage."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's very vague. I guess we can improve it later (in a separate PR)

text = "Variable shadowing",
defaultLevel = Levels.Warning,
description = "Checks for multiple uses of the variable name in nested scopes.",
explanation = "Variable shadowing is very useful, but can easily lead to nasty bugs in your code. Shadowed variables can be potentially confusing to other maintainers when the same name is adopted to have a new meaning in a nested scope."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is surprising:

Variable shadowing is very useful

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously this is quite subjective like a lot of other inspections. Some languages disallow variable shadowing, some allow it in some form. I personally find it useful in small and isolated scopes where otherwise I would have to make up an arbitrary name because another identifier in the scope is already using it.

text = "Avoid Traversable.size == 0",
defaultLevel = Levels.Warning,
description = "Checks for use of Traversable.size.",
explanation = "Traversable.size can be slow for some data structure, prefer Traversable.isEmpty, which is O(1)."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
explanation = "Traversable.size can be slow for some data structure, prefer Traversable.isEmpty, which is O(1)."
explanation = "Traversable.size can be slow for some data structure, prefer .isEmpty, which is O(1)."

@mwz
Copy link
Contributor Author

mwz commented Mar 12, 2020

Thanks, @mccartney for fixing all the typos.

@mccartney mccartney merged commit 78942be into scapegoat-scala:master Mar 12, 2020
@mwz mwz deleted the add-descriptions branch March 12, 2020 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants